package com.tedu.openmedical.brregister.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.tedu.openmedical.base.response.JsonResult;
import com.tedu.openmedical.brregister.pojo.dto.AddRegister;
import com.tedu.openmedical.brregister.pojo.entity.BrRegister;
import com.tedu.openmedical.brregister.service.BrRegisterService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 病案借阅登记表 前端控制器
 * </p>
 *
 * @author testjava
 * @since 2024-08-07
 */
@RestController
@RequestMapping("/lend/brRegister")
//跨域
@CrossOrigin
@Slf4j
public class BrRegisterController {
    @Autowired
    private BrRegisterService registerService;
    //selectAll:查询所有病案借阅登记表
    @GetMapping("/select/selectAll")
    public JsonResult selectAll(){
        QueryWrapper<BrRegister> brQueryWrapper = new QueryWrapper<>();
        brQueryWrapper.orderByAsc("br_medical_record_status");
        brQueryWrapper.orderByDesc("br_enroll");
        List<BrRegister> brDataAll = registerService.list(brQueryWrapper);
        return JsonResult.ok(brDataAll);
    }
    //selectOne：根据讲师id查询
    @GetMapping("/select/selectOne/{id}")
    public JsonResult selectOne(@PathVariable String id){
        BrRegister brRegister = registerService.getById(id);
        return JsonResult.ok(brRegister);
    }
    //addRegister：新增病案借阅登记表
    @PostMapping("/save/addRegister")
    public JsonResult addRegister(@RequestBody AddRegister addRegister){
        registerService.addRegister(addRegister);
        return JsonResult.ok();
    }

    //addRegister：新增病案借阅登记表
    @PostMapping("/update/updateStatusCancel/{id}")
    public JsonResult updateStatusCancel(@PathVariable String id){
        registerService.updateStatusCancel(id);
        return JsonResult.ok();
    }
}
